package com.kaifamiao.uploader.controller;

import com.kaifamiao.uploader.entity.FileInfo;
import com.kaifamiao.uploader.entity.Resp;
import com.kaifamiao.uploader.service.FileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/file")
public class FileInfoController {

    @Autowired
    private FileInfoService fileInfoService;

    /**
     * 验证文件是否已经上传过
     */
    @RequestMapping("/check")
    public Resp checkFileMd5(@RequestParam("md5") String md5) {
        FileInfo fileInfo = fileInfoService.checkFile(md5);
        if (fileInfo == null) {
            return Resp.success(201, "文件未上传");
        }
        return Resp.success("文件已上传").put("path", fileInfo.getLocation());
    }
}
